<template>
  <view class="tn-safe-area-inset-bottom">
    <!-- 顶部自定义导航 -->
    <tn-nav-bar fixed alpha customBack>
      <view slot="back" class='tn-custom-nav-bar__back'
        @click="goBack">
        <text class='icon tn-icon-left'></text>
        <text class='icon tn-icon-home-capsule-fill'></text>
      </view>
    </tn-nav-bar>
    
    
    <view class="adver-wrap" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
       <view class="tn-shadow tn-bg-white tn-margin">
         <view class="tn-text-center tn-color-blue" style="padding: 30rpx 0;">
           <text style="font-size: 80rpx;margin-left: -20rpx;">{{ score }}</text>
           <text class="tn-text-lg tn-padding-left-xs" style="font-size: 24rpx;">积分</text>
         </view>
         <view class="tn-flex-1 justify-content-item tn-margin-xs tn-text-center tn-padding-top tn-padding-bottom-xl">
           <tn-button shape="round" :plain="true" backgroundColor="#3668fc" padding="40rpx 0" width="70%" shadow :fontSize="32" @click="tn('/pageA/author/publish')">
             <text class="tn-color-blue--dark">发布日签最高领 200积分</text>
           </tn-button>
         </view>  
       </view>
     </view>
     
     <view class="">
       <view class="">
				 
				 <view class="tn-flex tn-flex-row-between tn-flex-col-center tn-padding tn-margin tn-shadow tn-bg-white">
				   <view class="justify-content-item">
				     <view class="tn-flex tn-flex-col-center tn-flex-row-left">
				       <view class="tn-margin-top-xs">
				         <view class="icon15__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur tn-bg-gray--light">
				           <view class="tn-icon-video-fill tn-color-gray"></view>
				         </view>
				       </view>
				       <view class="tn-padding-right tn-color-black" style="width: 400rpx;">
				         <view class="tn-padding-right tn-padding-left-sm tn-text-ellipsis tn-text-lg">
				           <text class="">阅读文章或视频</text>
				         </view>
				         <view class="tn-padding-right tn-padding-top-xs tn-text-sm tn-padding-left-sm tn-text-ellipsis tn-color-gray">
				           看完最高领取 100积分
				         </view>
				       </view>
				     </view>
				   </view>
				   <view class="justify-content-item tn-flex-row-center" @click="showAd()">
				 						 <tn-button  shape="round" backgroundColor="#FAD8D6" fontColor="#E83A30" :plain="true" width="70" fontSize="24">领积分</tn-button>
				     <!-- <view class="tn-bg-red--light tn-padding-xs tn-color-white tn-round tn-shadow-blur tn-text-sm">
				       <text class="tn-padding-xs tn-color-red">领积分</text>
				     </view> -->
				   </view>
				 </view>
				 
				 <!-- 分享好友开始 -->
         <view class="tn-flex tn-flex-row-between tn-flex-col-center tn-padding tn-margin tn-shadow tn-bg-white">
           <view class="justify-content-item">
             <view class="tn-flex tn-flex-col-center tn-flex-row-left">
               <view class="tn-margin-top-xs">
                 <view class="icon15__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur tn-bg-gray--light">
                   <view class="tn-icon-wechat-fill tn-color-gray"></view>
                 </view>
               </view>
               <view class="tn-padding-right tn-color-black" style="width: 400rpx;">
                 <view class="tn-padding-right tn-padding-left-sm tn-text-ellipsis tn-text-lg">
                   <text class="">分享微信好友助力</text>
                 </view>
                 <view class="tn-padding-right tn-padding-top-xs tn-text-sm tn-padding-left-sm tn-text-ellipsis tn-color-gray">
                   每次最高领取 100积分
                 </view>
               </view>
             </view>
           </view>
           <view class="justify-content-item tn-flex-row-center">
             <!-- <view class="tn-bg-red--light tn-padding-xs tn-color-white tn-round tn-shadow-blur tn-text-sm"> -->
               <!-- <text class="tn-padding-xs tn-color-red">领积分</text> -->
							 <tn-button openType="share" shape="round" backgroundColor="#FAD8D6" fontColor="#E83A30" :plain="true" width="70" fontSize="24">领积分</tn-button>
             <!-- </view> -->
           </view>
         </view>
				 <!-- 分享好友结束 -->
				 
				 <!-- 积分充值开始 -->
				 <view class="tn-flex tn-flex-row-between tn-flex-col-center tn-padding tn-margin tn-shadow tn-bg-white">
				   <view class="justify-content-item">
				     <view class="tn-flex tn-flex-col-center tn-flex-row-left">
				       <view class="tn-margin-top-xs">
				         <view class="icon15__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur tn-bg-gray--light">
				           <view class="tn-icon-money tn-color-gray"></view>
				         </view>
				       </view>
				       <view class="tn-padding-right tn-color-black" style="width: 400rpx;">
				         <view class="tn-padding-right tn-padding-left-sm tn-text-ellipsis tn-text-lg">
				           <text class="">积分充值</text>
				         </view>
				         <view class="tn-padding-right tn-padding-top-xs tn-text-sm tn-padding-left-sm tn-text-ellipsis tn-color-gray">
				           添加官方客服进行充值
				         </view>
				       </view>
				     </view>
				   </view>
				   <view class="justify-content-item tn-flex-row-center" @click="showRechargeModal">
				 			<tn-button shape="round" backgroundColor="#FAD8D6" fontColor="#E83A30" :plain="true" width="70" fontSize="24">领积分</tn-button>
				     <!-- <view class="tn-bg-red--light tn-padding-xs tn-color-white tn-round tn-shadow-blur tn-text-sm">
				       <text class="tn-padding-xs tn-color-red">领积分</text>
				     </view> -->
				   </view>
				 </view>
				 <!-- 积分充值结束 -->
				 
				 <!-- 发布日签开始 -->
				 <view class="tn-flex tn-flex-row-between tn-flex-col-center tn-padding tn-margin tn-shadow tn-bg-white">
				   <view class="justify-content-item">
				     <view class="tn-flex tn-flex-col-center tn-flex-row-left">
				       <view class="tn-margin-top-xs">
				         <view class="icon15__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur tn-bg-gray--light">
				           <view class="tn-icon-edit-write tn-color-gray"></view>
				         </view>
				       </view>
				       <view class="tn-padding-right tn-color-black" style="width: 400rpx;">
				         <view class="tn-padding-right tn-padding-left-sm tn-text-ellipsis tn-text-lg">
				           <text class="">发布作品</text>
				         </view>
				         <view class="tn-padding-right tn-padding-top-xs tn-text-sm tn-padding-left-sm tn-text-ellipsis tn-color-gray">
				           每次最高领取 200积分
				         </view>
				       </view>
				     </view>
				   </view>
				   <view class="justify-content-item tn-flex-row-center" @click="tn('/pageA/author/publish')">
						 <tn-button shape="round" backgroundColor="#FAD8D6" fontColor="#E83A30" :plain="true" width="70" fontSize="24">领积分</tn-button>
				     <!-- <view class="tn-bg-red--light tn-padding-xs tn-color-white tn-round tn-shadow-blur tn-text-sm">
				       <text class="tn-padding-xs tn-color-red">领积分</text>
				     </view> -->
				   </view>
				 </view>
				 <!-- 发布日签结束 -->
				 
				 <!-- 软件更新开始 -->
				 <view class="tn-flex tn-flex-row-between tn-flex-col-center tn-padding tn-margin tn-shadow tn-bg-white">
				   <view class="justify-content-item">
				     <view class="tn-flex tn-flex-col-center tn-flex-row-left">
				       <view class="tn-margin-top-xs">
				         <view class="icon15__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur tn-bg-gray--light">
				           <view class="tn-icon-notice tn-color-gray"></view>
				         </view>
				       </view>
				       <view class="tn-padding-right tn-color-black" style="width: 400rpx;">
				         <view class="tn-padding-right tn-padding-left-sm tn-text-ellipsis tn-text-lg">
				           <text class="">消息订阅</text>
				         </view>
				         <view class="tn-padding-right tn-padding-top-xs tn-text-sm tn-padding-left-sm tn-text-ellipsis tn-color-gray">
				           每次最高领取 200积分
				         </view>
				       </view>
				     </view>
				   </view>
				   <view class="justify-content-item tn-flex-row-center" @click="subscribe">
				 						 <tn-button shape="round" backgroundColor="#FAD8D6" fontColor="#E83A30" :plain="true" width="70" fontSize="24">领积分</tn-button>
				     <!-- <view class="tn-bg-red--light tn-padding-xs tn-color-white tn-round tn-shadow-blur tn-text-sm">
				       <text class="tn-padding-xs tn-color-red">领积分</text>
				     </view> -->
				   </view>
				 </view>
				 <!-- 软件更新结束 -->
				 
       </view>
       
     </view>
		 
		 <tn-modal v-model="showRechage" :custom="true">
		 	<view class="custom-modal-content">
		 		<image @tap="previewQRCodeImage" :src="qrUrl" mode='aspectFill'
		 			style="width: 100%;"></image>
		 		<view class="tn-text-center tn-padding-top" @click="tn('/pageA/about/about?uid=482928805799789437')">积分规则：了解积分规则</view>
		 		<view class="tn-text-center tn-padding-top">作者微信：haha_27092217</view>
		 		<view class="tn-text-center tn-padding-top tn-text-lg">长按识别客服微信二维码</view>
		 	</view>
		 </tn-modal>
    
    <view class='tn-tabbar-height'></view>
    
  </view>
</template>

<script>
  import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import { userScore, userScoreAdd } from "@/utils/api/user.js"
  export default {
    name: 'TemplateTask',
    mixins: [template_page_mixin],
    data(){
      return {
				score: 0.00,
				showRechage: false,
				qrUrl: getApp().globalData.qrUrl
			}
    },
		onShow() {
			this.getUserScore()
		},
		onLoad() {
		},
    methods: {
			// 显示充值客服弹窗
			showRechargeModal() {
				this.showRechage = true
			},
			// 预览作者图片
			previewQRCodeImage() {
				wx.previewImage({
					urls: [this.qrUrl]
				})
			},
			// 消息订阅
			async subscribe() {
				let result = await this.$func.templateSubscribe(getApp().globalData.appUpdate)
				this.score = (parseFloat(this.score) + parseFloat(result.score)).toFixed(2)
				this.$func.showToast("获取" + result.score + "积分")
			},
			async showAd() {
				if (getApp().globalData.showAd) {
					let _that = this
					let videoAd = null
					let adIdArray = getApp().globalData.rewardedVideoAd
					let index = await this.$func.randomIntFromInterval(0, adIdArray.length - 1)
					if (uni.createRewardedVideoAd) {
					  videoAd = uni.createRewardedVideoAd({
					    adUnitId: adIdArray[index]
					  })
					  videoAd.onLoad(() => {})
					  videoAd.onError((err) => {
							console.log("error", err)
							_that.$func.showToast(err.errMsg)
						})
					  videoAd.onClose((res) => {
							console.log("ad close", res)
							if (res.isEnded) {
								userScoreAdd({
									title: "观看广告"
								}).then(res => {
									if (res.code == 0) {
										_that.$func.showToast("获得" + res.score + "积分")
										_that.score = (parseFloat(res.score) + parseFloat(_that.score)).toFixed(2)
										return
									}
									_that.$func.showToast(res.errMsg)
								})
							}
						})
					}
					if (videoAd) {
					  videoAd.show().catch(() => {
					    // 失败重试
					    videoAd.load()
					      .then(() => videoAd.show())
					      .catch(err => {
									console.log(err)
					        _that.$func.showToast(err.errMsg)
					      })
					  })
					}
				}
			},
			getUserScore() {
				userScore().then(res => {
					this.score = res.score
				})
			},
      // 跳转
      tn(e) {
      	uni.navigateTo({
      		url: e,
      	});
      },
    }
  }
</script>

<style lang="scss" scoped>
  /* 胶囊*/
  .tn-custom-nav-bar__back {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    box-sizing: border-box;
    background-color: rgba(0, 0, 0, 0.15);
    border-radius: 1000rpx;
    border: 1rpx solid rgba(255, 255, 255, 0.5);
    color: #FFFFFF;
    font-size: 18px;
    
    .icon {
      display: block;
      flex: 1;
      margin: auto;
      text-align: center;
    }
    
    &:before {
      content: " ";
      width: 1rpx;
      height: 110%;
      position: absolute;
      top: 22.5%;
      left: 0;
      right: 0;
      margin: auto;
      transform: scale(0.5);
      transform-origin: 0 0;
      pointer-events: none;
      box-sizing: border-box;
      opacity: 0.7;
      background-color: #FFFFFF;
    }
  }
  
  /* 图标容器15 start */
  .icon15 {
    &__item {
      width: 30%;
      background-color: #FFFFFF;
      border-radius: 10rpx;
      padding: 30rpx;
      margin: 20rpx 10rpx;
      transform: scale(1);
      transition: transform 0.3s linear;
      transform-origin: center center;
      
      &--icon {
        width: 90rpx;
        height: 90rpx;
        font-size: 50rpx;
        border-radius: 50%;
        margin-bottom: 18rpx;
        position: relative;
        z-index: 1;
        
        &::after {
          content: " ";
          position: absolute;
          z-index: -1;
          width: 100%;
          height: 100%;
          left: 0;
          bottom: 0;
          border-radius: inherit;
          opacity: 1;
          transform: scale(1, 1);
          background-size: 100% 100%;
  
            
        }
      }
    }
  }
  
  
  /* 内容 */
   .adver-wrap {
     position: relative;
     z-index: 1;
     // padding: 20rpx 30rpx;
     // margin-top: -220rpx;  
     border-radius: 80rpx 80rpx 0 0;
   }
  
   
   .user-pic {
     background-size: cover;
     background-repeat: no-repeat;
     // background-attachment:fixed;
     background-position: top;
     border-radius: 50%;
     overflow: hidden;
     background-color: #FFFFFF;
   }
   
   
   /* 截图图片 start */
   .screenshot-img {
     z-index: -1;
     padding: 20rpx;
   
     image {
       width: 100%;
       display: block;
     }
   }
   
   
   
   /* 阴影 start*/
   .tn-shadow {
     border-radius: 15rpx;
     box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
   }
   
   /* 标题 start */
   .nav_title {
     -webkit-background-clip: text;
     color: transparent;
     
     &--wrap {
       position: relative;
       display: flex;
       height: 120rpx;
       align-items: center;
       justify-content: center;
       font-weight: bold;
       background-image: url(https://tnuiimage.tnkjapp.com/title_bg/title44.png);
       background-size: cover;
     }
   }
   /* 标题 end */
   /* 标题2 start */
   .nav_title2 {
     -webkit-background-clip: text;
     color: transparent;
     
     &--wrap {
       position: relative;
       display: flex;
       height: 120rpx;
       align-items: center;
       justify-content: center;
       font-weight: bold;
       // background-image: url(https://tnuiimage.tnkjapp.com/title_bg/title44.png);
       background-size: cover;
     }
   }
   /* 标题2 end */
   
  /* 店铺主图 start*/
   .image-article {
     border-radius: 16rpx;
     border: 1rpx solid #F8F7F8;
     width: 200rpx;
     height: 200rpx;
     position: relative;
   }
   
   .image-pic {
     background-size: cover;
     background-repeat: no-repeat;
     // background-attachment:fixed;
     background-position: top;
     border-radius: 20rpx;
   }
   
   .article-shadow {
     border-radius: 15rpx;
     box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
   }
   
   /* 文字截取*/
   .clamp-text-1 {
     -webkit-line-clamp: 1;
     display: -webkit-box;
     -webkit-box-orient: vertical;
     text-overflow: ellipsis;
     overflow: hidden;
   }
   
   .clamp-text-2 {
     -webkit-line-clamp: 2;
     display: -webkit-box;
     -webkit-box-orient: vertical;
     text-overflow: ellipsis;
     overflow: hidden;
   }
   
   /* 标签内容 start*/
   .tn-tag-content {
     &__item {
       display: inline-block;
       line-height: 35rpx;
       padding: 5rpx 25rpx;
   
       &--prefix {
         padding-right: 10rpx;
       }
     }
   }
</style>
